<?php

require('base.php');

class Article extends Base {
	
	function Article() {
		parent::Base();
		$this->database();	
	}
	
	function index($language) {
		$this->language( $language, 'base' );
		$this->lib('pagination');
		$total = $this->db->count('article', "language='$language'");
		$config = array(
			'total_row' => $total,
			'page_size' => 8
		);
		$this->pagination->init( $config );
		$sql = "select * from article where language='$language' order by created limit " . $this->pagination->start_row . "," . $this->pagination->page_size;
		$article_list = $this->db->find($sql);
		
		$page = $this->db->find_row("select * from page where language='$language' and url_pattern='news'");
		
		$meta = array(
			'title' 		=> $page['title'],
			'keywords'		=> $page['keywords'],
			'description'	=> $page['description']
		);
		
		$data = array(
			'news_list'	=> $article_list,
			'meta'		=> $meta
		);

		$this->layout('portal/article_list', $data);
	}
	
	function show($up, $language) {
		$this->language( $language, 'base' );	
		$article = $this->db->find_row("select * from article where language='$language' and url_pattern='$up'");
		
		$pre_article = $this->db->find_row("select title, url_pattern from article where language='$language' and id < ". $article['id'] ." order by id desc limit 0,1");
		$next_article = $this->db->find_row("select title, url_pattern from article where language='$language' and id > ". $article['id'] ." order by id limit 0,1");
		
		$meta = array(
			'title' 		=> $article['title'],
			'keywords'		=> $article['keywords'],
			'description'	=> $article['description']
		);
		
		$data = array(
			'article' 		=> $article,
			'pre_article' 	=> $pre_article,
			'next_article' 	=> $next_article,
			'meta'			=> $meta
		);
		 
		$this->layout('portal/article', $data);
	}
	
}

?>